#!/usr/bin/env python
import sys

args = sys.argv[1:]

final = ''

last = args[-1]
if last.startswith(']'):
    args = args[:-1]
    if len(last) > 1 and last[1] in ['+', '*', '?']:
        final = '\\%s' % last[1]

xs = []
for arg in args:

    # args like az aZ 09 will expand to a-z a-Z 0-9
    if len(arg) == 2:
        xs += ['%s-%s' % (arg[0], arg[1])]
        continue

    if arg == '-':
        xs += [r'\-']
        continue

    xs += [arg]

expr = ''.join(xs)

sys.stdout.write( '[%s]%s' % (expr, final) )
